package base.game;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import base.src.Images;

public class ShipArmored extends BaseShip {
	
	@Override
	public void onDraw(Canvas canvas, Paint paint) {
		canvas.drawBitmap(Images.shipArmorPlated.getImage(), Images.shipArmorPlated.getArea(), area, paint);
	}
	
	
	@Override
	public void onUpdate(long difftime) {
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see base.game.BaseShip#move(base.game.Map, float, float)
	 */
	@Override
	public boolean move(Map map, float touchX, float touchY) {
		if (canBePlaced(map, touchX, touchY)) {
			int grid[][] = map.getGrid();
			if (points != null) {
				for (int i = 0; i < points.length; i++) {
					int x = points[i][0];
					int y = points[i][1];
					grid[x][y] = 0;
				}
			}
			area = new RectF(Map.mapStartX + touchX * Map.rowWidth, Map.mapStartY + touchY * Map.rowHeight, 0, 0);
			area.right = area.left + Map.rowWidth * 4;
			area.bottom = area.top + Map.rowHeight;
			points = new int[4][3];
			points[0][0] = (int) touchX;
			points[0][1] = (int) touchY;
			points[0][2] = 0;
			points[1][0] = (int) touchX + 1;
			points[1][1] = (int) touchY;
			points[1][2] = 0;
			points[2][0] = (int) touchX + 2;
			points[2][1] = (int) touchY;
			points[2][2] = 0;
			points[3][0] = (int) touchX + 3;
			points[3][1] = (int) touchY;
			points[3][2] = 0;
			for (int i = 0; i < points.length; i++) {
				int x = points[i][0];
				int y = points[i][1];
				grid[x][y] = 1;
			}
		}
		return false;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see base.game.BaseShip#canBePlaced(base.game.Map, float, float)
	 */
	@Override
	public boolean canBePlaced(Map map, float touchX, float touchY) {
		return map.isValidAndFreePosition((int) touchX, (int) touchY) && map.isValidAndFreePosition((int) touchX + 1, (int) touchY)
				&& map.isValidAndFreePosition((int) touchX + 2, (int) touchY) && map.isValidAndFreePosition((int) touchX + 3, (int) touchY);
	}
	
}
